<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>
<!-- 1.this的问题：setinterval函数里面this是object windown。如果使用箭头函数的话，箭头函数内部的this永远和外面的this保持一致
    2.bug提示：Uncaught TypeError: Cannot read property ‘substring‘ of undefined。原因：获取的值为空，无法使用substring方法。
    3.清定时器：ting方法里无法访问到pao方法里面的变量，可以访问到data里面的 -->

<body>
    <div id="a">
        <input type="button" value="跑" @click='pao'>
        <input type="button" value="停" @click='ting'>
        <p>{{content}}</p>
    </div>
    <script>
        new Vue({
            el: '#a',
            data: {
                content: '猥琐发育，别浪',
                intervalid: null

            },
            methods: {
                pao: function() {
                    if (this.intervalid != null) return;
                    var that = this;
                    this.intervalid = setInterval(function() {
                        var start = that.content.substring(0, 1);
                        var end = that.content.substring(1);
                        that.content = end + start;
                    }, 1000)

                },
                ting: function() {
                    clearInterval(this.intervalid);

                    this.intervalid = null;
                }
            }
        })
    </script>
</body>

</html>